package com.yu.model;

import java.lang.reflect.Method;

public class User extends Object {
	
	String username;
	String password;
	
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public void setUsername(String username,Integer a) {
		this.username = username;
		System.out.println("a:" + a);
	}
	
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	

	
	/**
	 * 调用
	 * 
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		
		String clazzName = "com.yu.model.User";
		//调用 User类里面的setUserName()方法
		
		// 可以通过“反射”来实现
		
		/*User u = new User();
		u.setUsername("张三");
		System.out.println(u.getUsername());*/
		
		User o = (User)Class.forName(clazzName).newInstance();
		Method m = o.getClass().getMethod("setUsername", String.class,Integer.class);
		//Method m2 = o.getClass().getMethod("setUsername", String.class);
		
		m.invoke(o, "赵六",10); // 相当于 o.setUsername("赵六",10);
		System.out.println(o.getUsername());
		
		/*if(o instanceof User) {
			System.out.println("o instanceof User");
			u = (User)o;
			u.setUsername("李四");
			System.out.println(u.getUsername());
		} else {
			System.out.println("o is not instanceof User");
		}*/
		
		// 写法1：Method[] mArray = o.getClass().getMethods();
		/*User u = new User();
		Method[] mArray = u.getClass().getMethods();*/
		
		
		
		/*for(Method m : mArray ) { // m = mArray[i] i从0开始，每循环一次加1
			String methodName = m.getName();
			System.out.println(methodName);
		}*/
		
		
		
		
		
		
		
		
		
		
	}
	

}
